import Vue from 'vue';

// 此处解决的问题是
/**
 * todo 页面内容高度不足支撑下拉刷新的时候，重新定义高度
 */

const calcHeight = function (el, binding) {
  // 需要定义下拉刷新或者上拉加载更多成功时的状态一个变量
  if (binding.value) {
    setTimeout(() => {
      let refreshTrackEl = el.querySelector('.van-pull-refresh__track');
      let screenHeight = window.screen.height;
      let clientHeight = document.body.clientHeight;
      let headerEl = document.getElementById('HeaderTop');
      let tabbarEl = document.querySelector('.tabbar');
      let noneHeight = headerEl ? headerEl.clientHeight : 0;
      noneHeight += tabbarEl ? tabbarEl.clientHeight : 0;
      refreshTrackEl.style.minHeight = (Math.max(clientHeight, screenHeight) - noneHeight - 40) + 'px'
    }, 200)
  }
};

Vue.directive('pull-down-container-height', {
  update: calcHeight,
  bind: calcHeight
});
